package com.qqls.youxiangousys.pj.sys.service.impl;

import com.qqls.youxiangousys.pj.common.entity.Pagination;
import com.qqls.youxiangousys.pj.common.util.Assert;
import com.qqls.youxiangousys.pj.sys.dao.SysCarouselDao;
import com.qqls.youxiangousys.pj.sys.entity.SysCarousel;
import com.qqls.youxiangousys.pj.sys.service.realm.SysCarouselService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SysCarouselServiceImpl implements SysCarouselService {

    @Autowired
    private SysCarouselDao carDao;
    //查所有
    public Pagination findAll(String carouselTitle, Integer curPage, Integer pageSize) {
        //验证参数
        Assert.isEmpty(curPage == null || pageSize == null,"请选择当前页码或条数！");
        //得到角色总条数
      Integer n = carDao.getCount(carouselTitle);
      Assert.isEmpty(n==0,"查询错误");
      Pagination pageObj = new Pagination(curPage,n,pageSize);
      curPage = pageObj.getCurPage();//得到当前页
      pageSize = pageObj.getPageSize();//得到每页条数
        //分页跳过条数=（当前页 - 1）*每页条数
      Integer start = (curPage - 1) * pageSize;
      List<SysCarousel> list= carDao.findCarousel(carouselTitle,start,pageSize);
      Assert.isEmpty(list==null || list.size()==0,"数据不存在或者已经被删除");
        pageObj.setPageData(list);
        return pageObj;
    }

    //状态
    public Integer updateValId(Integer id, Integer carState) {
        Assert.isEmpty(id==0 || id==null,"请选择用户！");
        Assert.isEmpty(carState == null,"操作有误！");
        int n=carDao.updateValId(id,carState);
        Assert.isEmpty(n==0,"修改失败");
        return n;
    }

    //添加
    public Integer addCar(SysCarousel car) {
        Assert.isEmpty(car == null,"请填写完整！");
        Integer n=carDao.addCar(car);
        Assert.isEmpty(n==0,"添加失败!!");
        return n;
    }

    //删除
    public Integer delete(Integer[] ids) {
        Assert.isEmpty(ids.length==0||ids==null,"请选择数据！");
        Integer n=carDao.delete(ids);
        Assert.isEmpty(n==0,"删除失败!");
        return n;
    }

   //修改
    public Integer updateCar(SysCarousel carousel) {
        Assert.isEmpty(carousel==null || carousel.getId() == 0,"请选择要修改的数据");
        int n=carDao.updateCar(carousel);
        Assert.isEmpty(n==0,"修改失败");
        return n;
    }
}
